package com.zide.ams.mapper;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.zide.ams.domain.po.AmsComment;
import com.zide.ams.domain.vo.result.AmsCommentResultVO;
import com.zide.ams.domain.vo.search.AmsCommentSearchVO;
import com.zide.common.core.domain.entity.UmsMember;
import com.zide.framework.config.mybatisplus.XianYingMapperPlus;
import org.apache.ibatis.annotations.Mapper;
import com.zide.common.core.domain.PageResult;

/**
 * 文章评论Mapper接口
 * 
 * @author zide
 * @date 2024-04-29
 */
@Mapper
public interface AmsCommentMapper extends XianYingMapperPlus<AmsComment> {

    default PageResult<AmsCommentResultVO> selectPage(AmsCommentSearchVO searchVO) {

        MPJLambdaWrapper<AmsComment> wrapper = new MPJLambdaWrapper<>();
        wrapper.selectAll(AmsComment.class)
                .selectAs(UmsMember::getAvatar,"avatar")
                .selectAs(UmsMember::getNickname,"nickname")
                .leftJoin(UmsMember.class,UmsMember::getId,AmsComment::getUserId)
                .eq(AmsComment::getParentId,0).eq(AmsComment::getArticleId,searchVO.getArticleId())
                .orderByDesc(AmsComment::getCreateTime);
        return selectJoinPage(searchVO,AmsCommentResultVO.class,wrapper);
    }

    default List<AmsCommentResultVO> selectChildrenList(List<Long> parentIds) {
        MPJLambdaWrapper<AmsComment> wrapper = new MPJLambdaWrapper<>();
        wrapper.selectAll(AmsComment.class)
                .selectAs(UmsMember::getAvatar,"avatar")
                .selectAs(UmsMember::getNickname,"nickname")
                .leftJoin(UmsMember.class,UmsMember::getId,AmsComment::getUserId)
                .in(AmsComment::getParentId, parentIds)
                .orderByDesc(AmsComment::getCreateTime);
        return selectJoinList(AmsCommentResultVO.class,wrapper);
    }
}
